import {request} from "../../request/request.js";
import regeneratorRuntime from "../../lib/runtime/runtime.js";
import {login} from "../../utils/asyncWx.js"
Page({
  // 获取用户信息
  async handleGetUserInfo(e) {
    try {
      //1.获取用户信息
      const {encrypedData,rawData,iv,signature} = e.detail;
      //2. 获取小程序登陆成功后的code值
      const {code} = await login();
      const loginPaarams = {encrypedData,rawData,iv,signature,code};
      //3.发送请求获取token
      const {token} = await request({url:"/user/wxlogin",data:loginPaarams,method:"POST"});
      //4.把token存储到缓存中 同时跳转回上一个页面
      wx.setStorageSync("token", token);
      wx.navigateBack({
        delta: 1
      });    
    } catch (error) {
      console.log(error);
    }
  }
})